/**
 * @author zyj
 * @date 2022年06月10日 10:02
 */
class Demo1 {
    String name = "徐腾";
    String password = "123";

    public  synchronized String getValue(){
        return "姓名"+name+"密码"+password;
    }

    public  synchronized void setValue(String name,String password){
        this.name = name;
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.password = password;
        System.out.println("赋值"+name+":"+password);
    }
}


public class Test2{
    public static void main(String[] args) {
        Demo1 demo1 = new Demo1();
        new Thread(){
            @Override
            public void run() {
                demo1.setValue("qq","234");
            }
        }.start();

        System.out.println(demo1.getValue());
    }
}